package com.lkd.controller;


import com.lkd.entity.Partner;
import com.lkd.service.PartnerService;
import com.lkd.vo.PageBean;
import com.lkd.vo.PartnerVo;
import com.lkd.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 合作商表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-19
 */
@RestController
public class PartnerController {

    @Autowired
    private PartnerService partnerService;


    //新增合作商
    @PostMapping("/api/user-service/partner")
    public Result addPartern (@RequestBody Partner partner) {
        boolean save = partnerService.save (partner);
        return Result.success (save);
    }

    //合作商搜索
    @GetMapping("/api/user-service/partner/search")
    public  Result searchPartern(
            String name,
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10")Integer pageSize
    ){
        PageBean<PartnerVo> pageBean = partnerService.searchPartern(pageIndex,pageSize,name);
        return Result.success (pageBean);
    }


    //获取合作商
    @GetMapping("/api/user-service/partner/{id}")
    public  Result selectParnter(@PathVariable Integer id){

        PartnerVo partnerVo=partnerService.selectParnter(id);

        return Result.success (partnerVo);
    }

    //修改合作商
    @PutMapping("/api/user-service/partner")
    public Result update(@RequestBody Partner partner){
        boolean update = partnerService.updateById (partner);
        return Result.success (partner);
    }
    //删除合作商
    @DeleteMapping("/api/user-service/partner/{id}")
    public Result delete(@PathVariable Integer id){
        boolean b = partnerService.removeById (id);
        return Result.success (b);
    }
}
